﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.1f1
 *Date:           2019-03-23
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using UnityEditor;
using System.IO;
using UnityEngine;
namespace IFramework
{
	public partial class ProjectSettingWindow
	{
        [MenuItem("IFramework/ProjectSettingWindow")]
        public static void ShowWindow()
        {
            GetWindow<ProjectSettingWindow>(false, "ProSetting", true);
        }
	}
    public partial class ProjectSettingWindow:EditorWindow
    {
        private ProjectSettingSto sto;
        private ProjectSetting projectSetting;
        private void OnEnable()
        {
            if (!File.Exists(ProjectInfo.ProjectSettingStoPath))
            {
                ProjectInfo.CreateNewSto();
            }
            sto = ScriptableObj.Load<ProjectSettingSto>(ProjectInfo.ProjectSettingStoPath);
            projectSetting = sto.projectSetting;
        }
        private void OnDisable()
        {
            ScriptableObj.Update<ProjectSettingSto>(sto);
        }
        private void OnDestroy()
        {
            ScriptableObj.Update<ProjectSettingSto>(sto);
        }
        private void OnGUI()
        {
            BeginWindows();
            DrawProjectSetting();
            EndWindows();
            Repaint();
        }
        private void DrawProjectSetting()
        {
            projectSetting.rect = GUILayout.Window(0, projectSetting.rect, DrawProjectSetting, "ProSetting");
        }
        private void DrawProjectSetting(int id)
        {
            projectSetting.Draw(id);
            GUI.DragWindow();
        }
    }
}
